using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace Commerce.Common
{
	/// <summary>
	/// Strongly-typed collection for the CskTaxRate class.
	/// </summary>
	[Serializable]
	public partial class TaxRateCollection : ActiveList<TaxRate, TaxRateCollection> 
	{	   
		public TaxRateCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the CSK_Tax_Rate table.
	/// </summary>
	[Serializable]
	public partial class TaxRate : ActiveRecord<TaxRate>
	{
		#region .ctors and Default Settings
		
		public TaxRate()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public TaxRate(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

		public TaxRate(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public TaxRate(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor
		public static Query CreateQuery() { return new Query(Schema); }

		
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("CSK_Tax_Rate", TableType.Table, DataService.GetInstance("dashCommerce"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarRateID = new TableSchema.TableColumn(schema);
				colvarRateID.ColumnName = "rateID";
				colvarRateID.DataType = DbType.Int32;
				colvarRateID.MaxLength = 0;
				colvarRateID.AutoIncrement = true;
				colvarRateID.IsNullable = false;
				colvarRateID.IsPrimaryKey = true;
				colvarRateID.IsForeignKey = false;
				colvarRateID.IsReadOnly = false;
				colvarRateID.DefaultSetting = @"";
				colvarRateID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarRateID);
				
				TableSchema.TableColumn colvarRate = new TableSchema.TableColumn(schema);
				colvarRate.ColumnName = "rate";
				colvarRate.DataType = DbType.Currency;
				colvarRate.MaxLength = 0;
				colvarRate.AutoIncrement = false;
				colvarRate.IsNullable = false;
				colvarRate.IsPrimaryKey = false;
				colvarRate.IsForeignKey = false;
				colvarRate.IsReadOnly = false;
				colvarRate.DefaultSetting = @"";
				colvarRate.ForeignKeyTableName = "";
				schema.Columns.Add(colvarRate);
				
				TableSchema.TableColumn colvarState = new TableSchema.TableColumn(schema);
				colvarState.ColumnName = "state";
				colvarState.DataType = DbType.String;
				colvarState.MaxLength = 50;
				colvarState.AutoIncrement = false;
				colvarState.IsNullable = false;
				colvarState.IsPrimaryKey = false;
				colvarState.IsForeignKey = false;
				colvarState.IsReadOnly = false;
				colvarState.DefaultSetting = @"";
				colvarState.ForeignKeyTableName = "";
				schema.Columns.Add(colvarState);
				
				TableSchema.TableColumn colvarZipCode = new TableSchema.TableColumn(schema);
				colvarZipCode.ColumnName = "zipCode";
				colvarZipCode.DataType = DbType.String;
				colvarZipCode.MaxLength = 50;
				colvarZipCode.AutoIncrement = false;
				colvarZipCode.IsNullable = true;
				colvarZipCode.IsPrimaryKey = false;
				colvarZipCode.IsForeignKey = false;
				colvarZipCode.IsReadOnly = false;
				colvarZipCode.DefaultSetting = @"";
				colvarZipCode.ForeignKeyTableName = "";
				schema.Columns.Add(colvarZipCode);
				
				TableSchema.TableColumn colvarIsFreightTaxed = new TableSchema.TableColumn(schema);
				colvarIsFreightTaxed.ColumnName = "IsFreightTaxed";
				colvarIsFreightTaxed.DataType = DbType.Boolean;
				colvarIsFreightTaxed.MaxLength = 0;
				colvarIsFreightTaxed.AutoIncrement = false;
				colvarIsFreightTaxed.IsNullable = true;
				colvarIsFreightTaxed.IsPrimaryKey = false;
				colvarIsFreightTaxed.IsForeignKey = false;
				colvarIsFreightTaxed.IsReadOnly = false;
				colvarIsFreightTaxed.DefaultSetting = @"";
				colvarIsFreightTaxed.ForeignKeyTableName = "";
				schema.Columns.Add(colvarIsFreightTaxed);
				
				TableSchema.TableColumn colvarCreatedOn = new TableSchema.TableColumn(schema);
				colvarCreatedOn.ColumnName = "createdOn";
				colvarCreatedOn.DataType = DbType.DateTime;
				colvarCreatedOn.MaxLength = 0;
				colvarCreatedOn.AutoIncrement = false;
				colvarCreatedOn.IsNullable = true;
				colvarCreatedOn.IsPrimaryKey = false;
				colvarCreatedOn.IsForeignKey = false;
				colvarCreatedOn.IsReadOnly = false;
				
						colvarCreatedOn.DefaultSetting = @"(getdate())";
				colvarCreatedOn.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCreatedOn);
				
				TableSchema.TableColumn colvarCreatedBy = new TableSchema.TableColumn(schema);
				colvarCreatedBy.ColumnName = "createdBy";
				colvarCreatedBy.DataType = DbType.String;
				colvarCreatedBy.MaxLength = 50;
				colvarCreatedBy.AutoIncrement = false;
				colvarCreatedBy.IsNullable = true;
				colvarCreatedBy.IsPrimaryKey = false;
				colvarCreatedBy.IsForeignKey = false;
				colvarCreatedBy.IsReadOnly = false;
				colvarCreatedBy.DefaultSetting = @"";
				colvarCreatedBy.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCreatedBy);
				
				TableSchema.TableColumn colvarModifiedOn = new TableSchema.TableColumn(schema);
				colvarModifiedOn.ColumnName = "modifiedOn";
				colvarModifiedOn.DataType = DbType.DateTime;
				colvarModifiedOn.MaxLength = 0;
				colvarModifiedOn.AutoIncrement = false;
				colvarModifiedOn.IsNullable = true;
				colvarModifiedOn.IsPrimaryKey = false;
				colvarModifiedOn.IsForeignKey = false;
				colvarModifiedOn.IsReadOnly = false;
				
						colvarModifiedOn.DefaultSetting = @"(getdate())";
				colvarModifiedOn.ForeignKeyTableName = "";
				schema.Columns.Add(colvarModifiedOn);
				
				TableSchema.TableColumn colvarModifiedBy = new TableSchema.TableColumn(schema);
				colvarModifiedBy.ColumnName = "modifiedBy";
				colvarModifiedBy.DataType = DbType.String;
				colvarModifiedBy.MaxLength = 50;
				colvarModifiedBy.AutoIncrement = false;
				colvarModifiedBy.IsNullable = true;
				colvarModifiedBy.IsPrimaryKey = false;
				colvarModifiedBy.IsForeignKey = false;
				colvarModifiedBy.IsReadOnly = false;
				colvarModifiedBy.DefaultSetting = @"";
				colvarModifiedBy.ForeignKeyTableName = "";
				schema.Columns.Add(colvarModifiedBy);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["dashCommerce"].AddSchema("CSK_Tax_Rate",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("RateID")]
		public int RateID 
		{
			get { return GetColumnValue<int>("rateID"); }

			set { SetColumnValue("rateID", value); }

		}

		  
		[XmlAttribute("Rate")]
		public decimal Rate 
		{
			get { return GetColumnValue<decimal>("rate"); }

			set { SetColumnValue("rate", value); }

		}

		  
		[XmlAttribute("State")]
		public string State 
		{
			get { return GetColumnValue<string>("state"); }

			set { SetColumnValue("state", value); }

		}

		  
		[XmlAttribute("ZipCode")]
		public string ZipCode 
		{
			get { return GetColumnValue<string>("zipCode"); }

			set { SetColumnValue("zipCode", value); }

		}

		  
		[XmlAttribute("IsFreightTaxed")]
		public bool? IsFreightTaxed 
		{
			get { return GetColumnValue<bool?>("IsFreightTaxed"); }

			set { SetColumnValue("IsFreightTaxed", value); }

		}

		  
		[XmlAttribute("CreatedOn")]
		public DateTime? CreatedOn 
		{
			get { return GetColumnValue<DateTime?>("createdOn"); }

			set { SetColumnValue("createdOn", value); }

		}

		  
		[XmlAttribute("CreatedBy")]
		public string CreatedBy 
		{
			get { return GetColumnValue<string>("createdBy"); }

			set { SetColumnValue("createdBy", value); }

		}

		  
		[XmlAttribute("ModifiedOn")]
		public DateTime? ModifiedOn 
		{
			get { return GetColumnValue<DateTime?>("modifiedOn"); }

			set { SetColumnValue("modifiedOn", value); }

		}

		  
		[XmlAttribute("ModifiedBy")]
		public string ModifiedBy 
		{
			get { return GetColumnValue<string>("modifiedBy"); }

			set { SetColumnValue("modifiedBy", value); }

		}

		
		#endregion
		
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(decimal varRate,string varState,string varZipCode,bool? varIsFreightTaxed,DateTime? varCreatedOn,string varCreatedBy,DateTime? varModifiedOn,string varModifiedBy)
		{
			TaxRate item = new TaxRate();
			
			item.Rate = varRate;
			
			item.State = varState;
			
			item.ZipCode = varZipCode;
			
			item.IsFreightTaxed = varIsFreightTaxed;
			
			item.CreatedOn = varCreatedOn;
			
			item.CreatedBy = varCreatedBy;
			
			item.ModifiedOn = varModifiedOn;
			
			item.ModifiedBy = varModifiedBy;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varRateID,decimal varRate,string varState,string varZipCode,bool? varIsFreightTaxed,DateTime? varCreatedOn,string varCreatedBy,DateTime? varModifiedOn,string varModifiedBy)
		{
			TaxRate item = new TaxRate();
			
				item.RateID = varRateID;
				
				item.Rate = varRate;
				
				item.State = varState;
				
				item.ZipCode = varZipCode;
				
				item.IsFreightTaxed = varIsFreightTaxed;
				
				item.CreatedOn = varCreatedOn;
				
				item.CreatedBy = varCreatedBy;
				
				item.ModifiedOn = varModifiedOn;
				
				item.ModifiedBy = varModifiedBy;
				
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string RateID = @"rateID";
			 public static string Rate = @"rate";
			 public static string State = @"state";
			 public static string ZipCode = @"zipCode";
			 public static string IsFreightTaxed = @"IsFreightTaxed";
			 public static string CreatedOn = @"createdOn";
			 public static string CreatedBy = @"createdBy";
			 public static string ModifiedOn = @"modifiedOn";
			 public static string ModifiedBy = @"modifiedBy";
						
		}

		#endregion
	}

}

